package com.ruoyi.system.service.wxapp;

import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.sign.Md5Utils;
import sun.misc.BASE64Encoder;

import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 何金岳
 * @Description TODO
 * @createTime 2024年04月12日10时30分56秒
 * @since 1.0.0
 */
public class SfAppTest {

    public static void main(String args[])throws Exception{
        /*
        //询价查询接口报文
        String msgm="{\"businessType\":\"2\",\"consignedTime\":\"2024-04-12 10:13:40\",\"destAddress\":{\"address\":\"海南省三沙市西山区101号\",\"city\":\"重庆市\",\"district\":\"\",\"province\":\"重庆市\"},\"searchPrice\":\"1\",\"srcAddress\":{\"address\":\"海南省文昌市铺前镇胜利街905号\",\"city\":\"文昌市\",\"district\":\"\",\"province\":\"海南省\"},\"weight\":6}";
        String verifyCode="mI3Z5O8Cjbd1VHcdlLP7EC5xJPz7mCrr";

        String systemMills=String.valueOf(System.currentTimeMillis());
        System.out.println(systemMills);
        String toVerifyText=msgm+systemMills+verifyCode;
        toVerifyText= URLEncoder.encode(toVerifyText,"UTF-8");
        MessageDigest md5=MessageDigest.getInstance("MD5");
        md5.update(toVerifyText.getBytes("UTF-8"));
        byte[] md=md5.digest();
        String msgDigest=new String(new BASE64Encoder().encode(md));
        System.out.println(msgDigest);
        String url="https://bspgw.sf-express.com/std/service";
        Map<String,String> params=new HashMap<>();
        params.put("partnerID","Y0AL0QLO");
        params.put("requestID","e3cbfd72-ae66-4570-a29f-4d0ec89cf33a");
        params.put("serviceCode","EXP_RECE_QUERY_DELIVERTM");
        params.put("timestamp",systemMills);
        params.put("msgDigest",msgDigest);
        params.put("msgData",msgm);
        String callback=HttpUtils.sendPost(url,params);
        System.out.println(callback);*/



        String msgm="{\"language\": \"zh-CN\",\"trackingType\": \"1\",\"trackingNumber\": [\"SF1524016671561\"],\"methodType\": \"1\",\"checkPhoneNo\":\"6707\"}";
        String verifyCode="mI3Z5O8Cjbd1VHcdlLP7EC5xJPz7mCrr";

        String systemMills=String.valueOf(System.currentTimeMillis());
        System.out.println(systemMills);
        String toVerifyText=msgm+systemMills+verifyCode;
        toVerifyText= URLEncoder.encode(toVerifyText,"UTF-8");
        MessageDigest md5=MessageDigest.getInstance("MD5");
        md5.update(toVerifyText.getBytes("UTF-8"));
        byte[] md=md5.digest();
        String msgDigest=new String(new BASE64Encoder().encode(md));
        System.out.println(msgDigest);
        String url="https://bspgw.sf-express.com/std/service";
        Map<String,String> params=new HashMap<>();
        params.put("partnerID","Y0AL0QLO");
        params.put("requestID","e3cbfd72-ae66-4570-a29f-4d0ec89cf33a");
        params.put("serviceCode","EXP_RECE_SEARCH_ROUTES");
        params.put("timestamp",systemMills);
        params.put("msgDigest",msgDigest);
        params.put("msgData",msgm);
        String callback=HttpUtils.sendPost(url,params);
        System.out.println(callback);
    }
}
